package com.ita.dom.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.Timestamp;
import java.util.List;

import com.ita.dom.dao.IWeiBoDao;
import com.ita.dom.entity.WeiBo;
import com.ita.uitl.DbUtil;

public class WeiBoDaoImpl implements IWeiBoDao {

	@SuppressWarnings("unused")
	public int insert(List<WeiBo> list) {
		int index=0;
 		String sql="Insert into RECORDS values(?,?,?,?,?,?,?,?)";
		Connection conn=DbUtil.getConnection();
		
		PreparedStatement ps;
		try {
			ps = conn.prepareStatement(sql);
			for (WeiBo weibo:list) {
	 			    index++;
	 				ps.setString(1, weibo.getId());
	 				ps.setString(2,weibo.getArticle());
	 				ps.setString(3, String.valueOf(weibo.getDiscuss()));
	 				ps.setTimestamp(4,new Timestamp(weibo.getInsertTime().getTime()));
	 				ps.setString(5, weibo.getOrigin());
	 				ps.setString(6,weibo.getPersonId());
	 				ps.setTimestamp(7, new Timestamp(weibo.getTime().getTime()));
	 				
	 				try{
	 					ps.setInt(8, Integer.valueOf(weibo.getTransmit()));
	 				}catch(NumberFormatException e){
	 					ps.setInt(8, 0);
	 				}
	 				int index1=ps.executeUpdate();
	 				System.out.println(weibo.toString());
		     
		}
		   System.out.println(index);
			
		    conn.commit();
		    DbUtil.free(conn, ps, null);
		}catch(Exception e){
			
		}
	 		
			return index;
	
	}

}
